// component/backtorule/backtorule.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isnavigator:{
      type:Boolean,
      value:false
    },
    iscsorderno:{
      type:Number,
      value:''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    tag:'y',
    myval:null,
    detail:null,
    flag:[0, 0, 0],  //每行标记变量 改变显示的五角星
    startext: ['', '', ''],   //各个下标对应每行显示  5个评价中的一个 非常不满意/不满意
    stardata: [1, 2, 3, 4, 5],  //每颗星星对应的数值  决定了渲染出几颗五角星
    xzhongxx:null,
  },

  /**
   * 组件的方法列表
   */
  methods: {
     /*关闭*/
     onisTrue(e){
      let that = this;
      that.setData({
        isnavigator:false
      })
    },
    // 五星评价事件
  changeColor: function (e) {
    var index = e.currentTarget.dataset.index;  //判断选中了哪个评价 在前端页面写死的索引
    var num = e.currentTarget.dataset.no; //前端页面的 item 传来选择了多少个
    console.log(num)
    var a = 'flag[' + index + ']';
    var b = 'startext[' + index + ']';
    console.log(a,b)
    var that = this;
    if(num == 1) {
      that.setData({
        [a]: 1,
        [b]: '非常不满意',
        xzhongxx:1
      });
    } else if (num == 2){
      that.setData({
        [a]: 2,
        [b]: '不满意',
        xzhongxx:2
      });
    } else if (num == 3) {
      that.setData({
        [a]: 3,
        [b]: '一般',
        xzhongxx:3
      });
    } else if (num == 4) {
      that.setData({
        [a]: 4,
        [b]: '满意',
        xzhongxx:4
      });
    } else if (num == 5) {
      that.setData({
        [a]: 5,
        [b]: '非常满意',
        xzhongxx:5
      });
    }
  //  console.log(that.properties.iscsorderno);
  },

  getmsg(e){
    let that = this
    let detail = e.detail.value
      console.log(e)
      console.log(that.properties.iscsorderno)
      that.setData({
        detail:detail 
      })
  },
    oknoinfo(e){
      let  that = this
      let  myval = that.data.myval
      let  detail = that.data.detail
      let  orderinfo=that.properties.iscsorderno   //传入订单号
      let  token = wx.getStorageSync('token')
      let   xx = that.data.xzhongxx
      console.log(xx);
      if(xx==null){
        wx.showToast({
          title: '请选择评价星级',
          icon: 'error',
          duration: 2000
        }) 
      }else{
        if(xx<'5' && detail==null){
          wx.showToast({
            title: '请输入评价',
            icon: 'error',
            duration: 2000
          })
        }else{

        wx.request({
          url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
          data: {
           //请求后台的分页数据
           cmd:'SaveComment',
           token:token,
           OrderNo:orderinfo,
           Service:xx,
           Descr:detail
          },
          method: "get",
          success(res) {
              if(res.data.STATUS=='Success'){
                wx.showToast({
                  title: '评论成功',
                  icon: 'success',
                  duration: 2000
                })
                that.setData({
                  isnavigator:false
                })
              }else{
                wx.showToast({
                  title: '评论失败',
                  icon: 'error',
                  duration: 2000
                })
              }
          }
        })

        }
      }
    }
  }
})
